package com.daniel.create.simfactory;

/**
 * @Description 简单工厂---简单工厂不是设计模式，更像是一种编程习惯。它把实例化的操作单独放到一个类中，这个类就成为简单工厂类，让简单工厂类来决定应该用哪个具体子类来实例化。
 * @Author GanShaoXi
 * @ClassName SimpleFactory
 * @Return com.daniel.create.simfactory
 * @Since 1.0.0
 * @Created on 2023/5/17 17:39
 */
public class FactoryMethod {
    /**
     * 测试
     * @param args
     */
    public static void main(String[] args) {
        // 需要水利工程
        WaterProjectFactory waterProjectFactory = new WaterProjectFactory();
        waterProjectFactory.Manufacture().work();

        // 需要电力工程
        ElectricityFactory electricityFactory = new ElectricityFactory();
        electricityFactory.Manufacture().work();
    }
}


abstract class BaseFactory {
    /**
     * 工厂的公共接口
     *
     * @return
     */
    public abstract BaseProduct Manufacture();
}

abstract class BaseProduct {
    /**
     * 工程的公共接口
     */
    public abstract void work();
}

/**
 * @Description 水利工程
 * @Author GanShaoXi
 * @ClassName FactoryMethod
 * @Return com.daniel.create.simfactory
 * @Since 1.0.0
 * @Created on 2023/5/17 20:09
 */
class WaterProject extends BaseProduct {
    @Override
    public void work() {
        System.out.println("Water conservancy works began irrigation");
    }
}

/**
 * @Description 电力工程
 * @Author GanShaoXi
 * @ClassName FactoryMethod
 * @Return com.daniel.create.simfactory
 * @Since 1.0.0
 * @Created on 2023/5/17 20:09
 */
class ElectricityProject extends BaseProduct {

    @Override
    public void work() {
        System.out.println("Power engineering began generating electricity");
    }
}

/**
 * @Description 水利工程工厂 - 建造水利工程
 * @Author GanShaoXi
 * @ClassName FactoryMethod
 * @Return com.daniel.create.simfactory
 * @Since 1.0.0
 * @Created on 2023/5/17 20:12
 */
class WaterProjectFactory extends BaseFactory {
    @Override
    public BaseProduct Manufacture() {
        return new WaterProject();
    }
}

/**
 * @Description 电力工程工厂 - 建造电力工程
 * @Author GanShaoXi
 * @ClassName FactoryMethod
 * @Return com.daniel.create.simfactory
 * @Since 1.0.0
 * @Created on 2023/5/17 20:12
 */
class ElectricityFactory extends BaseFactory {
    @Override
    public BaseProduct Manufacture() {
        return new ElectricityProject();
    }
}